package com.bawei.park2211a.login

import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.mvvm.BaseActivity
import com.bawei.park2211a.R
import com.bawei.park2211a.databinding.ActivityLoginBinding
import com.blankj.utilcode.util.RegexUtils
import com.blankj.utilcode.util.SPUtils

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/login/LoginActivity")
class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>() {

    override fun initView() {
        binding.userLogin.setOnClickListener {
            viewModel.login(
                binding.etUserName.text.toString(),
                binding.etUserPassword.text.toString()
            )
        }


        binding.etUserName.setText(SPUtils.getInstance().getString("username"))
        binding.etUserPassword.setText(SPUtils.getInstance().getString("password"))
    }

    override fun initData() {
        viewModel.loginSuccess.observe(this) {
            SPUtils.getInstance().put("token", it.token)
            SPUtils.getInstance().put("username", it.username)
            SPUtils.getInstance().put("password", it.password)
            ARouter.getInstance().build("/app/MainActivity").navigation()
        }
    }
}